<?php
/**
 * Description
 *
 * PHP version 7
 *
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-25 11:44:44
 * @lastTime 2020-05-01 23:01:17
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */

namespace Design\Structural\FluentInterface;

class Sql
{

    private $field = [];

    private $from;

    private $where = [];


    public function select(array $field)
    {
        $this->field = $field;
        return $this;

    }//end select()


    public function from(string $table, string $alias='')
    {
        $table      .= empty($alias) === true ? '' : ' AS '.$alias;
        $this->table = $table;
        return $this;

    }//end from()


    public function where(string $condition)
    {
        $this->where[] = $condition;
        return $this;

    }//end where()


    public function __toString(): string
    {
        return sprintf(
            'SELECT %s FROM %s WHERE %s',
            implode(',', $this->field),
            $this->table,
            implode(' AND ', $this->where)
        );

    }//end __toString()


}//end class
